package com.vm.activity;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

import org.json.JSONObject;

import com.alipay.sdk.app.PayTask;
import com.alipay.sdk.pay.PayResult;
import com.alipay.sdk.pay.SignUtils;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.ImageLoader.ImageListener;
import com.vm.commons.CurrentGoods;
import com.vm.commons.CurrentUser;
import com.vm.commons.VMConst;
import com.vm.db.LocalUserInfoDao;
import com.vm.model.UserAddress;
import com.vm.utils.ApkUtils;
import com.vm.utils.JsonUtils;
import com.vm.utils.MyVolley;
import com.wwtscapp.apk.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * @ProjectName: [WeiMai]
 * @Author: [kent.wang]
 * @CreateDate: [2015年3月18日 上午9:33:18]
 * @Version: [v1.0]
 * 
 */
public class OrderConfirmActivity extends Activity {

	// 商户PID
	public static final String PARTNER = "2088712200989071";
	// 商户收款账号
	public static final String SELLER = "zhifubao@weimaikeji.com";
	// 商户私钥，pkcs8格式
	public static final String RSA_PRIVATE = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAN6gZ8XfMYPCN/rGbZCikUpFDGUqX6qG9U1mNtWHejb25hI86+YRxZ51tbDzRjUcZm2KXFCC5nCD2l4+t9QndaWyvCfYhSWl9mIvcVNN8YClE7JwBeUpqLVqE3zwd9gCOaYhjYhO73FgeSv9TrBrQCxf/RFiXJG/e2dTPUHbex7FAgMBAAECgYBOCPPXDBETGjT9Fii5lgJPgjyCCYRXBc9ePgHifwZ71bd3lRsrHfejP6dcSynE3BubMfCB2CBmOBGHD3zoRJybvNUdsXA/7i1aCA9TXGBbDnVxtoLiIt7I/9zu9EiDddevsDhXBZKXHic4QCFZ7H8TZlRyEY1qpSrBx5Mg9WbA0QJBAPJxAfs+FTW25URngtVgQin88dQCFVBb8sh9SQvPwa1HhK1lfki2QhXsgCfabys/7L3DGDTqfasAueRl5rr9fNsCQQDrE7Y3s15f9qYAYAfh2+pKOl3fw4auGG3zrJfRrFMm3R5KNcbqhhIV7HucHI0NnnMxRcgTuyLlH7WnTxTHstTfAkEAic56ldkgLTwc7dj4oVjpwvwoaZ4Vh2v8gMHWN4SMTnaMkBNUyPfwcI3R+tVKw4a+hs7Sf6GadQ0gnRbfJALaaQJAFXqDl6tH4DTFDhu4HKbfTVDv6tYOpDGPOkh2xq2cG1zwu48WUa9WT7J/yM/DA4+KruHVWhgrJAw1qMfM+kIYuQJBAMGsHLMBLjjpbiLw5BML5DPRsGQSWq3Re/Am+VGGTDD8ftovj1/jO4sZVW5QGuPl8s9SVdEo8+KWNtRxLXej7vc=";
	// 支付宝公钥
	public static final String RSA_PUBLIC = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";

	private static final int SDK_PAY_FLAG = 1;

	private static final int SDK_CHECK_FLAG = 2;

	// ImageView iv_select;
	LinearLayout llayout_address;
	ImageView iv_goodsImage;
	ImageView imgbtn_search_back;
	TextView tv_name;
	TextView tv_phone;
	TextView tv_goodsName;
	TextView tv_address;
	TextView tv_goodsPrice;
	TextView tv_integral;
	Button btn_confirm;
	TextView tv_order_number;
	TextView tv_order_status;
	TextView tv_number;
	TextView tv_total_order_money;
	TextView tv_total_goods_money;
	EditText et_note;
	TextView tv_money;
	TextView tv_using_integra3;
	TextView tv_using_integra4;
	CheckBox cb_use_integra;
	TextView tv_using_preferential_money;
	TextView tv_freight_amount_money;
	private LocalUserInfoDao luidao;
	UserAddress userAddress;
	RequestQueue mQueue;
	ImageLoader mImageLoader;
	TextView imgbtn_sub1;
	TextView imgbtn_add1;
	EditText tv_num1;
	String num;
	Float totalPrice;
	ScrollView scrollView1;
	Float integer;
	Float totalprice;
	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case SDK_PAY_FLAG: {
				PayResult payResult = new PayResult((String) msg.obj);

				payResult.getResult();

				String resultStatus = payResult.getResultStatus();

				// 判断resultStatus 为“9000”则代表支付成功，具体状态码代表含义可参考接口文档
				if (TextUtils.equals(resultStatus, "9000")) {
					Toast.makeText(OrderConfirmActivity.this, "支付成功",
							Toast.LENGTH_SHORT).show();
					btn_confirm.setEnabled(true);
					addOrder();
				} else {
					// 判断resultStatus 为非“9000”则代表可能支付失败
					// “8000”代表支付结果因为支付渠道原因或者系统原因还在等待支付结果确认，最终交易是否成功以服务端异步通知为准（小概率状态）
					if (TextUtils.equals(resultStatus, "8000")) {
						Toast.makeText(OrderConfirmActivity.this, "支付结果确认中",
								Toast.LENGTH_SHORT).show();

					} else {
						// 其他值就可以判断为支付失败，包括用户主动取消支付，或者系统返回的错误
						Toast.makeText(OrderConfirmActivity.this, "支付失败",
								Toast.LENGTH_SHORT).show();
						btn_confirm.setEnabled(true);
					}
				}
				break;
			}
			case SDK_CHECK_FLAG: {
				Toast.makeText(OrderConfirmActivity.this, "检查结果为：" + msg.obj,
						Toast.LENGTH_SHORT).show();
				break;
			}
			default:
				break;
			}
		};
	};

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.order_confirm);

		init();
		luidao = new LocalUserInfoDao(this);

		// tv_goodsPrice.setText(Float.toString(goods.getPrice()));
		// tv_integral.setText(Integer.toString(goods.getIntegral()));

		mQueue = MyVolley.getRequestQueue();
		mImageLoader = new ImageLoader(mQueue, new BitmapCache());
		ImageListener listener = ImageLoader
				.getImageListener(iv_goodsImage,
						android.R.drawable.ic_menu_rotate,
						android.R.drawable.ic_delete);

		mImageLoader.get(VMConst.URL + CurrentGoods.GOODSIMG, listener);
		userAddress = (UserAddress) getIntent().getSerializableExtra(
				"userAddress");
		if (userAddress != null) {
			tv_name.setText(userAddress.getName());
			tv_phone.setText(userAddress.getTelephone());
			tv_address
					.setText(userAddress.getArea() + userAddress.getAddress());
		} else {
			String url = VMConst.REQUEST_URL + "getFirstAddress?userId="
					+ CurrentUser.USERID;
			JsonObjectRequest addressRequest = new JsonObjectRequest(url, null,
					new Listener<JSONObject>() {

						@Override
						public void onResponse(JSONObject arg0) {
							userAddress = JsonUtils.jsonToBean(arg0,
									UserAddress.class);
							if (userAddress != null) {
								tv_name.setText(userAddress.getName());
								tv_phone.setText(userAddress.getTelephone());
								tv_address.setText(userAddress.getArea()
										+ userAddress.getAddress());
							}
						}
					}, new ErrorListener() {

						@Override
						public void onErrorResponse(VolleyError arg0) {
							tv_address.setText("请点击创建收货地址");
						}
					});
			mQueue.add(addressRequest);
		}

	}

	/**
	 * 初始化
	 */
	public void init() {
		num = Integer.toString(CurrentGoods.NUM);
		scrollView1 = (ScrollView) findViewById(R.id.scrollView1);
		scrollView1.smoothScrollTo(0, 20);
		totalPrice = Integer.parseInt(num) * CurrentGoods.GODOSPRICE;
		tv_name = (TextView) findViewById(R.id.tv_name);
		tv_phone = (TextView) findViewById(R.id.tv_phone);
		tv_address = (TextView) findViewById(R.id.tv_address);
		tv_order_number = (TextView) findViewById(R.id.tv_order_number);
		tv_order_status = (TextView) findViewById(R.id.tv_order_status);
		tv_number = (TextView) findViewById(R.id.tv_number);
		tv_total_order_money = (TextView) findViewById(R.id.tv_total_order_money);
		tv_total_goods_money = (TextView) findViewById(R.id.tv_total_goods_money);
		et_note = (EditText) findViewById(R.id.et_note);
		tv_money = (TextView) findViewById(R.id.tv_money);
		btn_confirm = (Button) findViewById(R.id.btn_confirm);
		tv_using_integra3 = (TextView) findViewById(R.id.tv_using_integra3);
		tv_using_integra4 = (TextView) findViewById(R.id.tv_using_integra4);
		cb_use_integra = (CheckBox) findViewById(R.id.cb_use_integra);
		tv_using_preferential_money = (TextView) findViewById(R.id.tv_using_preferential_money);
		tv_freight_amount_money = (TextView) findViewById(R.id.tv_freight_amount_money);
		iv_goodsImage = (ImageView) findViewById(R.id.iv_goodsImage);
		imgbtn_search_back = (ImageView) findViewById(R.id.imgbtn_search_back);
		tv_goodsName = (TextView) findViewById(R.id.tv_goodsName);
		tv_goodsPrice = (TextView) findViewById(R.id.tv_goodsPrice);
		// tv_integral = (TextView) findViewById(R.id.tv_integral);
		tv_goodsPrice.setText(Float.toString(CurrentGoods.GODOSPRICE));
		btn_confirm = (Button) findViewById(R.id.btn_confirm);

		btn_confirm.setOnClickListener(btn_confirmListener);
		llayout_address = (LinearLayout) findViewById(R.id.llayout_address);
		llayout_address.setOnClickListener(address_ClickListener);
		imgbtn_search_back.setOnClickListener(btn_backListener);
		// iv_select = (ImageView)findViewById(R.id.iv_select);
		// iv_select.setOnClickListener(ClickListener);
		tv_goodsName.setText(CurrentGoods.GOODSNAME);
		imgbtn_sub1 = (TextView) findViewById(R.id.imgbtn_sub1);
		imgbtn_add1 = (TextView) findViewById(R.id.imgbtn_add1);
		imgbtn_sub1.setOnClickListener(num_listener);
		imgbtn_add1.setOnClickListener(num_listener);
		tv_num1 = (EditText) findViewById(R.id.tv_num1);
		tv_num1.addTextChangedListener(textWatcher);
		initData();
		cb_use_integra
				.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						// TODO Auto-generated method stub

						if (isChecked) {
							tv_using_integra3.setVisibility(View.VISIBLE);
							// 如果用户积分可兑换的金额小于订单价格
							if (totalPrice * 100 > CurrentUser.INTERGRAL) {
								tv_using_integra3.setText(CurrentUser.INTERGRAL
										.toString());
								integer = Float
										.parseFloat(CurrentUser.INTERGRAL
												.toString());
							} else {
								tv_using_integra3.setText(Float
										.toString(totalPrice * 100));
								integer = totalPrice * 100;
							}
							tv_using_preferential_money.setText(Float
									.toString(integer / 100));
							tv_total_order_money.setText(Float
									.toString(totalPrice - integer / 100));
							double total = Double
									.parseDouble(tv_total_order_money.getText()
											.toString()) + 8;
							tv_money.setText(Double.toString(total));
						} else {
							tv_using_integra3.setVisibility(View.GONE);
							tv_using_preferential_money.setText("0.00");
							tv_total_order_money.setText(Float
									.toString(totalPrice));
							// tv_money.setText(tv_total_order_money.getText()
							// .toString());

							double total = totalPrice + 8;
							tv_money.setText(Double.toString(total));
						}
					}

				});

	}

	OnClickListener address_ClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(OrderConfirmActivity.this,
					AddressManageActivity.class);
			// intent.putExtra("userId", userInfo.getUserId());
			intent.putExtra("order", 1);
			startActivity(intent);

			OrderConfirmActivity.this.finish();
		}
	};

	/**
	 * imgbtn_search_back 返回按钮监听
	 */
	OnClickListener btn_backListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			onBackPressed();
		}
	};

	/**
	 * 手机自带返回按钮监听
	 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();

	}

	public void initData() {
		tv_num1.setText(num);
		tv_number.setText(num);
		totalPrice = Integer.parseInt(num) * CurrentGoods.GODOSPRICE;
		tv_total_goods_money.setText(Float.toString(totalPrice));
		tv_using_integra4.setText(CurrentUser.INTERGRAL.toString());
		tv_total_order_money.setText(Float.toString(totalPrice));
		// tv_money.setText(tv_total_order_money.getText().toString());
		double total = Double
				.parseDouble(Float.toString(totalPrice).toString()) + 8;
		tv_money.setText(Double.toString(total));

	}

	OnClickListener num_listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			// 判断EditText的内容是否为正整数，不是设为1
			cb_use_integra.setChecked(false);
			for (int j = 0; j < num.length(); j++) {
				if (!(num.charAt(j) >= 48 && num.charAt(j) <= 57)
						|| Integer.parseInt(num) == 0) {
					System.out.println("您输入的不是正整数!请重新输入.");
					tv_num1.setText(Integer.toString(CurrentGoods.NUM));
					num = Integer.toString(CurrentGoods.NUM);
				}
			}
			tv_num1.setCursorVisible(false);
			switch (v.getId()) {
			case R.id.imgbtn_sub1:
				if (num.equals("1")) {

				} else {
					int i = Integer.parseInt(num);
					i--;
					// String.valueOf(i);
					tv_num1.setText(String.valueOf(i));
				}
				initNum();
				initData();
				break;
			case R.id.imgbtn_add1:
				int i = Integer.parseInt(num);
				i++;
				tv_num1.setText(String.valueOf(i));
				initNum();
				initData();
				break;
			}

		}

	};

	public void initNum() {
		num = tv_num1.getText().toString();

		if (num.equals("1")) {
			imgbtn_sub1
					.setTextColor(this.getResources().getColor(R.color.sub1));
		} else {
			imgbtn_sub1.setTextColor(this.getResources().getColor(R.color.sub));
		}
	}

	private TextWatcher textWatcher = new TextWatcher() {

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			// TODO Auto-generated method stub
		}

		@Override
		public void afterTextChanged(Editable s) {
			// TODO Auto-generated method stub
			// tv_num1.setCursorVisible(false);
			initNum();
			for (int j = 0; j < num.length(); j++) {
				if ((num.charAt(j) >= 48 && num.charAt(j) <= 57)
						&& !(Integer.parseInt(num) == 0)) {
					tv_number.setText(num);
					totalPrice = Integer.parseInt(num)
							* CurrentGoods.GODOSPRICE;
					tv_total_goods_money.setText(Float.toString(totalPrice));
					tv_using_integra4.setText(CurrentUser.INTERGRAL.toString());
					tv_total_order_money.setText(Float.toString(totalPrice));
					double total = Double.parseDouble(Float
							.toString(totalPrice).toString()) + 8;
					tv_money.setText(Double.toString(total));
					// tv_money.setText(tv_total_order_money.getText().toString());
					cb_use_integra.setChecked(false);
				}
			}

		}

	};

	/**
	 * 增加订单
	 */
	private void addOrder() {

		final String sUsedIntegrity = tv_using_integra3.getText().toString();
		if (sUsedIntegrity != null) {
			Integer.parseInt(sUsedIntegrity);
		}

		String url = VMConst.REQUEST_URL + "confirmOrder?userId="
				+ CurrentUser.USERID + "&goodsId=" + CurrentGoods.GOODSID
				+ "&addressId=" + userAddress.getId() + "&number=" + num
				+ "&integrity=" + sUsedIntegrity;
		StringRequest confirmRequest = new StringRequest(url,
				new Listener<String>() {

					@Override
					public void onResponse(String arg0) {
						if (arg0.equals("1")) {
							// 成功
							CurrentUser.INTERGRAL = CurrentUser.INTERGRAL
									- Integer.parseInt(sUsedIntegrity);

							luidao.update();
							// Intent intent = new Intent(
							// OrderConfirmActivity.this,
							// GoodsDetailsActivity.class);
							// startActivity(intent);
						} else {
							// 失败
							Toast toast = Toast.makeText(
									OrderConfirmActivity.this, "订单提交失败",
									Toast.LENGTH_SHORT);
							toast.show();
						}
					}
				}, new ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError arg0) {
						// //提示积分不足
						Toast toast = Toast.makeText(OrderConfirmActivity.this,
								"订单提交失败", Toast.LENGTH_SHORT);
						toast.show();
					}
				});
		mQueue.add(confirmRequest);
		btn_confirm.setEnabled(true);
	}

	/**
	 * 确认支付
	 */
	OnClickListener btn_confirmListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (userAddress != null) {
				btn_confirm.setEnabled(false);
				double money = 0;
				String s_money = tv_money.getText().toString();
				if (s_money != null) {
					money += Double.parseDouble(s_money);
				}
				check(v);
				// 当需要支付的金额大于0,弹出支付
				if (ApkUtils.isAppInstalled("com.eg.android.AlipayGphone",
						OrderConfirmActivity.this)) {
					pay(money);
				} else {
					Toast toast = Toast.makeText(OrderConfirmActivity.this,
							"请先下载支付宝钱包", Toast.LENGTH_SHORT);
					toast.show();
					Intent intent = new Intent(OrderConfirmActivity.this,
							DetailActivity.class);
					intent.putExtra("softId",
							"5b1bffb4-abd5-4cc0-b142-40078ca10814");
					startActivity(intent);
				}

			}

		}
	};

	/**
	 * call alipay sdk pay. 调用SDK支付
	 * 
	 */
	public void pay(Double money) {
		// 订单
		String name = tv_name.getText().toString();
		String orderInfo = getOrderInfo(name, name, Double.toString(money));

		// 对订单做RSA 签名
		String sign = sign(orderInfo);
		try {
			// 仅需对sign 做URL编码
			sign = URLEncoder.encode(sign, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		// 完整的符合支付宝参数规范的订单信息
		final String payInfo = orderInfo + "&sign=\"" + sign + "\"&"
				+ getSignType();

		Runnable payRunnable = new Runnable() {

			@Override
			public void run() {
				// 构造PayTask 对象
				PayTask alipay = new PayTask(OrderConfirmActivity.this);
				// 调用支付接口，获取支付结果
				String result = alipay.pay(payInfo);

				Message msg = new Message();
				msg.what = SDK_PAY_FLAG;
				msg.obj = result;
				mHandler.sendMessage(msg);
			}
		};

		// 必须异步调用
		Thread payThread = new Thread(payRunnable);
		payThread.start();
	}

	/**
	 * check whether the device has authentication alipay account.
	 * 查询终端设备是否存在支付宝认证账户
	 * 
	 */
	public void check(View v) {
		Runnable checkRunnable = new Runnable() {

			@Override
			public void run() {
				// 构造PayTask 对象
				PayTask payTask = new PayTask(OrderConfirmActivity.this);
				// 调用查询接口，获取查询结果
				boolean isExist = payTask.checkAccountIfExist();

				Message msg = new Message();
				msg.what = SDK_CHECK_FLAG;
				msg.obj = isExist;
				mHandler.sendMessage(msg);
			}
		};

		Thread checkThread = new Thread(checkRunnable);
		checkThread.start();

	}

	/**
	 * get the sdk version. 获取SDK版本号
	 * 
	 */
	public void getSDKVersion() {
		PayTask payTask = new PayTask(this);
		String version = payTask.getVersion();
		Toast.makeText(this, version, Toast.LENGTH_SHORT).show();
	}

	/**
	 * create the order info. 创建订单信息
	 * 
	 */
	public String getOrderInfo(String subject, String body, String price) {
		// 签约合作者身份ID
		String orderInfo = "partner=" + "\"" + PARTNER + "\"";

		// 签约卖家支付宝账号
		orderInfo += "&seller_id=" + "\"" + SELLER + "\"";

		// 商户网站唯一订单号
		orderInfo += "&out_trade_no=" + "\"" + getOutTradeNo() + "\"";

		// 商品名称
		orderInfo += "&subject=" + "\"" + subject + "\"";

		// 商品详情
		orderInfo += "&body=" + "\"" + body + "\"";

		// 商品金额
		orderInfo += "&total_fee=" + "\"" + price + "\"";

		// 服务器异步通知页面路径
		orderInfo += "&notify_url=" + "\"" + "http://notify.msp.hk/notify.htm"
				+ "\"";

		// 服务接口名称， 固定值
		orderInfo += "&service=\"mobile.securitypay.pay\"";

		// 支付类型， 固定值
		orderInfo += "&payment_type=\"1\"";

		// 参数编码， 固定值
		orderInfo += "&_input_charset=\"utf-8\"";

		// 设置未付款交易的超时时间
		// 默认30分钟，一旦超时，该笔交易就会自动被关闭。
		// 取值范围：1m～15d。
		// m-分钟，h-小时，d-天，1c-当天（无论交易何时创建，都在0点关闭）。
		// 该参数数值不接受小数点，如1.5h，可转换为90m。
		orderInfo += "&it_b_pay=\"30m\"";

		// extern_token为经过快登授权获取到的alipay_open_id,带上此参数用户将使用授权的账户进行支付
		// orderInfo += "&extern_token=" + "\"" + extern_token + "\"";

		// 支付宝处理完请求后，当前页面跳转到商户指定页面的路径，可空
		orderInfo += "&return_url=\"m.alipay.com\"";

		// 调用银行卡支付，需配置此参数，参与签名， 固定值 （需要签约《无线银行卡快捷支付》才能使用）
		// orderInfo += "&paymethod=\"expressGateway\"";

		return orderInfo;
	}

	/**
	 * get the out_trade_no for an order. 生成商户订单号，该值在商户端应保持唯一（可自定义格式规范）
	 * 
	 */
	public String getOutTradeNo() {
		SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss",
				Locale.getDefault());
		Date date = new Date();
		String key = format.format(date);

		Random r = new Random();
		key = key + r.nextInt();
		key = key.substring(0, 15);
		return key;
	}

	/**
	 * sign the order info. 对订单信息进行签名
	 * 
	 * @param content
	 *            待签名订单信息
	 */
	public String sign(String content) {
		return SignUtils.sign(content, RSA_PRIVATE);
	}

	/**
	 * get the sign type we use. 获取签名方式
	 * 
	 */
	public String getSignType() {
		return "sign_type=\"RSA\"";
	}
}
